home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / util / wb / ProcessIcon.lha / Source / ProcessIcon.c
Encoding:
C/C++ Source or Header  |  1999-10-11  |  8.3 KB  |  305 lines

  1. #define NAME     "ProcessIcon"
  2. #define REVISION "12"
  3. #define SDI_ENDCODE
  4.  
  5. /* Programmheader
  6.  
  7.     Name:        ProcessIcon
  8.     Author:        SDI
  9.     Distribution:    PD
  10.     Description:    processes .info files
  11.     Compileropts:    -
  12.     Linkeropts:    -l amiga
  13.  
  14.  1.0   01.93.97 : first version
  15.  1.1   03.03.97 : options KILLSTACKSIZE, KILLDEFTOOL, VIEW
  16.  1.2   05.03.97 : added SIT and CIT options
  17.  1.3   29.03.97 : not existing TO produces icon
  18.  1.4   13.06.97 : lots of changes, renamed from CopyIconImage
  19.  1.5   14.06.97 : added more data to VIEW option
  20.  1.6   01.07.97 : fixed problem with DrawerData
  21.  1.7   09.11.97 : added UNSNAP function
  22.  1.8   05.02.98 : IMGSRC became REFICON, added CII instead of autocopy
  23.  1.9   01.09.98 : better VIEW output
  24.  1.10  08.05.99 : added REMAP option
  25.  1.11  21.09.99 : KTT removes entry totally
  26.  1.12  11.10.99 : add SSS option
  27. */
  28.  
  29. #include <proto/dos.h>
  30. #include <proto/icon.h>
  31. #include <proto/exec.h>
  32. #define SDI_TO_ANSI
  33. #include "SDI_ASM_STD_protos.h"
  34. #include "SDI_defines.h"
  35.  
  36. #define PARAM (STRPTR)  "ICON/A,REFICON,VIEW/S,OPT=OPTIMIZE/S,"        \
  37.             "US=UNSNAP/S,REMAP/S,"                \
  38.             "SDT=SETDEFTOOL,SSS=SETSTACKSIZE/N,"        \
  39.             "SIT=SETICONTYPE,SBP=SETBITPLANES/N,"        \
  40.             "SXP=SETXPOS/N,SYP=SETYPOS/N,"            \
  41.             "KDT=KILLDEFTOOL/S,KTT=KILLTOOLTYPES/S,"    \
  42.             "KSS=KILLSTACKSIZE/S,KDD=KILLDRAWERDATA/S,"    \
  43.             "CDT=COPYDEFTOOL/S,CIT=COPYICONTYPE/S,"        \
  44.             "CTT=COPYTOOLTYPES/S,CDD=COPYDRAWERDATA/S,"    \
  45.             "CII=COPYICONIMAGE/S"
  46. struct Args {
  47.     STRPTR    icon;
  48.     STRPTR    reficon;
  49.     ULONG    view;
  50.     ULONG    optimize;
  51.     ULONG     unsnap;
  52.     ULONG    remap;
  53.     STRPTR    setdeftool;
  54.     ULONG *     setstacksize;
  55.     STRPTR    seticontype;
  56.     ULONG *    setbitplanes;
  57.     ULONG *    setxpos;
  58.     ULONG *    setypos;
  59.     ULONG    killdeftool;
  60.     ULONG    killtooltypes;
  61.     ULONG    killstacksize;
  62.     ULONG    killdrawerdata;
  63.     ULONG    copydeftool;
  64.     ULONG    copyicontype;
  65.     ULONG    copytooltypes;
  66.     ULONG    copydrawerdata;
  67.     ULONG    copyiconimage;
  68. };
  69.  
  70. struct RDArgs*        rda        = 0;
  71. struct Library *    IconBase    = 0;
  72. ULONG            DosVersion    = 37;
  73. struct DiskObject *    dobj        = 0;
  74. struct DiskObject *    dobjsrc        = 0;
  75. struct DiskObject *    dobjdrw        = 0;
  76.  
  77. STRPTR IconTypeRecog[] = 
  78. {0, "Disk", "Drawer", "Tool", "Project", "Garbage", "Device", "Kick", "AppIcon"};
  79.  
  80. static void testgroup(APTR a, ULONG b, ULONG c)
  81. {
  82.   if((a && (b || c)) || (b && c))
  83.   {
  84.     SetIoErr(ERROR_TOO_MANY_ARGS);
  85.     End(RETURN_FAIL);
  86.   }
  87. }
  88.  
  89. static void kill(ULONG a, APTR b)
  90. {
  91.   if(a && *((ULONG *)b))
  92.     *((ULONG *)b) = 0;
  93. }
  94.  
  95. static void set(STRPTR a, APTR b)
  96. {
  97.   if(a)
  98.     *((STRPTR *)b) = a;
  99. }
  100.  
  101. static void RemapImage(struct Image *im)
  102. {
  103.   ULONG w, i, j, k, d;
  104.   UWORD *ptr;
  105.  
  106.   w = (im->Width+15)>>4; /* dive by 16 */
  107.   ptr = im->ImageData;
  108.  
  109.   if(im->Depth == 1)
  110.   {
  111.     for(i = 0; i < im->Height; ++i)
  112.     {
  113.       for(j = 0; j < w; ++j)
  114.         ptr[i*w + j] ^= 0xFFFF;
  115.       if((k = (w<<4) - im->Width))
  116.       {
  117.         /* clear last unused bits */
  118.         ptr[i*w + j - 1] &= (0xFFFF >> k) << k;
  119.       }
  120.     }
  121.   }
  122.   else
  123.   {
  124.     for(i = 0; i < im->Height; ++i)
  125.     {
  126.       for(j = 0; j < w; ++j)
  127.       {
  128.         k = ptr[i*w + j] ^ ptr[(im->Height + i)*w + j];
  129.         for(d = 2; d < im->Depth; ++d)
  130.           k &= (~ptr[(im->Height*d +i)*w + j]);
  131.         ptr[i*w + j] ^= k;
  132.         ptr[(im->Height + i)*w + j] ^= k;
  133.       }
  134.       if((k = (w<<4) - im->Width))
  135.       {
  136.         /* clear last unused bits */
  137.         ptr[i*w + j - 1] &= (0xFFFF >> k) << k;
  138.         ptr[(im->Height + i)*w + j - 1] &= (0xFFFF >> k) << k;
  139.       }
  140.     }
  141.   }
  142. }
  143.  
  144. void main(void)
  145. {
  146.   struct Args args;
  147.   ULONG s;
  148.  
  149.   memset(&args, 0, sizeof(struct Args));
  150.  
  151.   if(!(rda = ReadArgs(PARAM, (LONG *) &args, 0)))
  152.     End(RETURN_FAIL);
  153.  
  154.   testgroup(args.setdeftool,    args.killdeftool,    args.copydeftool);
  155.   testgroup(0,            args.killtooltypes,    args.copytooltypes);
  156.   testgroup(args.seticontype,    0,            args.copyicontype);
  157.   testgroup(0,            args.killdrawerdata,    args.copydrawerdata);
  158.   testgroup(args.setstacksize,  args.killstacksize,     0);
  159.  
  160.   if((args.unsnap && (args.setxpos || args.setypos)) || (!args.reficon &&
  161.   (args.copydeftool || args.copytooltypes || args.copyicontype ||
  162.   args.copydrawerdata || args.copyiconimage)))
  163.   {
  164.     SetIoErr(ERROR_TOO_MANY_ARGS);
  165.     End(RETURN_FAIL);
  166.   }
  167.  
  168.   s = strlen(args.icon);
  169.   if(!strncmp(args.icon+s-5, ".info",5))
  170.     args.icon[s-5] = 0;
  171.  
  172.   if(
  173.   !(IconBase = OpenLibrary("icon.library", 37)) ||
  174.   !(dobj = GetDiskObjectNew(args.icon)) ||
  175.   !(dobjdrw = GetDefDiskObject(WBDRAWER)))
  176.     End(RETURN_FAIL);
  177.  
  178.   if(args.view)
  179.   {
  180.     STRPTR *a;
  181.  
  182.     Printf("Name: %s\n SS: %ld\n IT: %s\n BP: %ld,%ld\n SZ: ",
  183.       args.icon, dobj->do_StackSize, IconTypeRecog[dobj->do_Type],
  184.       ((struct Image *)dobj->do_Gadget.GadgetRender)->Depth,
  185.       (dobj->do_Gadget.SelectRender ?
  186.       ((struct Image *)dobj->do_Gadget.SelectRender)->Depth : 0));
  187.     Printf(dobj->do_CurrentX == NO_ICON_POSITION ? "NOPOS" : "x=%3ld",
  188.       dobj->do_CurrentX);
  189.     Printf(dobj->do_CurrentY == NO_ICON_POSITION ? ", NOPOS" : ", y=%3ld",
  190.       dobj->do_CurrentY);
  191.     Printf(", w=%3ld, h=%3ld\n DT: (%s) %s\n TT: (%s)\n",
  192.       dobj->do_Gadget.Width, dobj->do_Gadget.Height,
  193.       (dobj->do_DefaultTool ? "YES" : "NO"), dobj->do_DefaultTool, 
  194.       (dobj->do_ToolTypes ? (*(dobj->do_ToolTypes) ? "YES" :
  195.       "YES - EMPTY") : "NO"));
  196.     if((a = (STRPTR *) dobj->do_ToolTypes))
  197.       while(*a)
  198.         Printf("  %s\n", *(a++));
  199.     End(RETURN_OK);
  200.   }
  201.  
  202.   if(args.reficon)
  203.   {
  204.     s = strlen(args.reficon);
  205.     if(!strncmp(args.reficon+s-5, ".info",5))
  206.       args.reficon[s-5] = 0;
  207.     if((dobjsrc = GetDiskObjectNew(args.reficon)))
  208.     {
  209.       if(args.copyiconimage)
  210.       {
  211.         if(dobj->do_CurrentX != NO_ICON_POSITION && dobj->do_CurrentY !=
  212.         NO_ICON_POSITION)
  213.         {
  214.           dobj->do_CurrentX +=
  215.             (dobj->do_Gadget.Width>>1) - (dobjsrc->do_Gadget.Width>>1);
  216.           dobj->do_CurrentY +=
  217.             dobj->do_Gadget.Height - dobjsrc->do_Gadget.Height;
  218.           /* 'down middle position' of gadget should be same after image copy */
  219.         }
  220.         dobj->do_Gadget = dobjsrc->do_Gadget;    /* copy gadget structures */
  221.       }
  222.       if(args.copydeftool)    dobj->do_DefaultTool = dobjsrc->do_DefaultTool;
  223.       if(args.copytooltypes)    dobj->do_ToolTypes = dobjsrc->do_ToolTypes;
  224.       if(args.copyicontype)    dobj->do_Type = dobjsrc->do_Type;
  225.       if(args.copydrawerdata)    dobj->do_DrawerData = dobjsrc->do_DrawerData;
  226.     }
  227.     else
  228.       End(RETURN_FAIL);
  229.   }
  230.  
  231.   if(args.seticontype)
  232.   {
  233.     UBYTE i = 0;
  234.  
  235.     while(++i <= WBAPPICON && stricmp(IconTypeRecog[i], args.seticontype))
  236.       ;
  237.     if(i <= WBAPPICON)
  238.       dobj->do_Type = i;
  239.  
  240.     if(dobj->do_Type == WBDISK || dobj->do_Type == WBGARBAGE ||
  241.        dobj->do_Type == WBDRAWER)
  242.       dobj->do_DrawerData = dobjdrw->do_DrawerData;
  243.   }
  244.  
  245.   if(args.remap)
  246.   {
  247.     RemapImage((struct Image *) dobj->do_Gadget.GadgetRender);
  248.     if(dobj->do_Gadget.SelectRender)
  249.       RemapImage((struct Image *) dobj->do_Gadget.SelectRender);
  250.   }
  251.  
  252.   if(args.setbitplanes)
  253.   {
  254.     ((struct Image *) dobj->do_Gadget.GadgetRender)->Depth =
  255.     *args.setbitplanes;
  256.     if(dobj->do_Gadget.SelectRender)
  257.       ((struct Image *) dobj->do_Gadget.SelectRender)->Depth =
  258.       *args.setbitplanes;
  259.   }
  260.  
  261.   if(args.setxpos)        dobj->do_CurrentX = *args.setxpos;
  262.   if(args.setypos)        dobj->do_CurrentY = *args.setypos;
  263.   if(args.setstacksize)        dobj->do_StackSize = *args.setstacksize;
  264.   set(args.setdeftool, &dobj->do_DefaultTool);
  265.  
  266.   if(args.killdrawerdata)
  267.   {
  268.     dobj->do_DrawerData = dobjdrw->do_DrawerData;
  269.     if(dobj->do_Type != WBDISK && dobj->do_Type != WBGARBAGE &&
  270.     dobj->do_Type != WBDRAWER)
  271.       dobj->do_DrawerData = 0;
  272.   }
  273.     
  274.   if(args.unsnap)        dobj->do_CurrentX = dobj->do_CurrentY = NO_ICON_POSITION;
  275.  
  276.   kill(args.killtooltypes, &dobj->do_ToolTypes);
  277.   kill(args.killstacksize, &dobj->do_StackSize);
  278.   kill(args.killdeftool, &dobj->do_DefaultTool);
  279.  
  280.   if(args.optimize)
  281.   {
  282.     if(dobj->do_Type != WBDISK && dobj->do_Type != WBPROJECT)
  283.       dobj->do_DefaultTool = 0;
  284.     if(dobj->do_Type != WBPROJECT && dobj->do_Type != WBTOOL)
  285.       dobj->do_ToolTypes = 0;
  286.     if(dobj->do_Type != WBDISK && dobj->do_Type != WBGARBAGE &&
  287.     dobj->do_Type != WBDRAWER)
  288.       dobj->do_DrawerData = 0;
  289.     if(dobj->do_ToolTypes && !(*dobj->do_ToolTypes))
  290.       dobj->do_ToolTypes = 0;
  291.   }
  292.  
  293.   End(PutDiskObject(args.icon, dobj) ? RETURN_OK : RETURN_FAIL);
  294. }
  295.  
  296. void end(void)
  297. {
  298.   if(dobj)        FreeDiskObject(dobj);
  299.   if(dobjdrw)        FreeDiskObject(dobjdrw);
  300.   if(dobjsrc)        FreeDiskObject(dobjsrc);
  301.   if(IconBase)        CloseLibrary(IconBase);
  302.   if(rda)        FreeArgs(rda);
  303. }
  304.  
  305.